<table width="100%" border="0" cellspacing="0" cellpadding="0" class="grey_line">
  <tr>
    <td class="grey_bg-1 black_txt-2" height="25">&nbsp; <strong>Search returns ${searchResults/resultsCount} results.</strong> </td>
  </tr>
  <?php if(count($ctx->searchResults['result'])>0) { ?>
  <tr>
    <td align="left"><a href="javascript:void(0);" class="l_gray_links1" onclick="CheckAll()">Check All</a> <span class="gray_txt_s">|</span> <a href="javascript:void(0);" class="l_gray_links1" onclick="ClearAll()">Uncheck All</a></td>
  </tr>
  <tal:block tal:omit-tag="" tal:repeat="list searchResults/result">
    <?php //print "<pre>";print_r($ctx->list);
if( $ctx->friends['photo'] != '' && file_exists('../'.$ctx->userImage . $ctx->friends['photo']) ){
	//echo 'TRUE';exit;
$image = '/'.$ctx->userImage.$ctx->friends['photo']."?".time();
} else { 
	$image = "/images/ProfileDefUser.gif?".time();
} 
    <tr>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="bot_border-3"><table width="100%" border="0" cellspacing="0" cellpadding="3">
                <tr>
                  <td width="4%" valign="top" align="center">
                  <?php if(!in_array($ctx->list['user_id'],$ctx->userConnectionsArray)){ ?>
                  <input type="checkbox" name="chk" id="" value="<?php echo urlencode($ctx->list['user_id']);?>" />
                  <?php } else { echo '&nbsp;';} ?>
                  </td>
                  <td width="4%"><a href="/user/profile/index/<?php echo base64_encode($ctx->list['user_id']);?>"><img src="<?=$image;?>" class="img_border" alt="<?php echo $ctx->list['name'];?>" title="<?php echo $ctx->list['name'];?>" height="33" width="35" /></a></td>
                  <td width="88%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="68%"><a href="/user/profile/index/<?php echo base64_encode($ctx->list['user_id']);?>" class="blue_text_link_3"><?php echo $ctx->list['name'];?></a></td>
                        <td width="32%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="8%"><!--<img src="/images/msg_icon.gif"  />--></td>
                              <td width="54%">&nbsp;<!--<a href="#" class="l_gray_links1">Send Message</a>--></td>
                              <?php if(!in_array($ctx->list['user_id'],$ctx->userConnectionsArray)){ ?>
                              <td width="9%"><img src="/images/invite_icon.gif" style="padding-right:5px;" /></td>
                              <td width="29%"><a href="javascript:void(0);" class="l_gray_links1" onclick="InviteAll('One','<?php echo urlencode($ctx->list['user_id']);?>');">Add To Contact</a></td>
                              <?php } else { echo '<td></td>&nbsp;<td></td>'; } ?>	
                            </tr>
                          </table></td>
                      </tr>

                    </table></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>
  </tal:block>
  <tr>
    <td class="grey_bg-1"><table width="98%" height="30" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr> 
          <!--<td align="center" width="18%"><a href="#" class="button_grey"><span >Send Message</span></a></td>-->
          <td align="center" width="14%"><a href="javascript:void(0);" class="Button" onclick="InviteAll('All');"><span >Add to Contact</span></a></td>
          <td width="68%"><div id="downPagerId" class="paginat" style="padding-right:15px;"></div></td>
        </tr>
      </table></td>
  </tr>
  <?php }  else {  ?>
  <tr>
    <td class="gray_txt_s1" align="center" height="50">No Results</td>
  </tr>
  <?php } ?>
</table>
<script type="text/javascript">
//<![CDATA[
pagination = new Array();
pagination['currentPage'] = "<?=$ctx->searchResults['currentPage']?>";
pagination['resultsPerPage'] = "<?=$ctx->searchResults['resultPerPage']?>";;
pagination['pages'] = "<?= $ctx->searchResults['pages']?>";  
pagination['pager'] = '<?=$ctx->searchResults["pager"]?>';
pagination['resultsCount'] = "${searchResults/resultsCount}" ;

var Params='sindividual=<?= urlencode($ctx->sindividual);?>';
					var requestUrl = "/contacts/index/search-pagination/0/";
$(document).ready(function () {
   setPagination(pagination['resultsCount'],'','downPagerId','','');
});

function CheckAll() {
	
	var checks = document.getElementsByTagName('INPUT');
	var len = checks.length;
	for (var i = 0; i < len; i++) {
	   if (checks[i].name == 'chk') {
			checks[i].checked=true
	   }
	}
	
}
function ClearAll() {
	var checks = document.getElementsByTagName('INPUT');
	var len = checks.length;
	for (var i = 0; i < len; i++) {
	   if (checks[i].name == 'chk')  {
			checks[i].checked=false
	   }
	}
}

function InviteAll(callType,Value) {		
   var oneSelected =0,list="";
   var checks = document.getElementsByTagName('INPUT');
   var len = checks.length;
   for (var i = 0; i < len; i++) {
	   if (checks[i].name == 'chk'  ) {
			if(checks[i].checked) {
					list += checks[i].value + ",";
					oneSelected++;
			}
		}
	}
	//alert(list);
	if(callType == 'All') {
		if( oneSelected ==0 ) {  alert('Select at least one member.'); return false; };
	}
if(callType == 'One' && Value!='')
{
		$.ajax({
			   type: "POST",
			   dataType: "json",
			   url: "/contacts/index/save-contact/",
			   data: {list:Value},
			   success: function(data){
					//window.location= '/contacts/';
					alert('1 Contact added Sucussfully');
					window.location = '/contacts/';
						//$('#listContent').html('Contacts added successfully');
			   }
		});
}
	else 
	{
			$.ajax({
			   type: "POST",
			   dataType: "json",
			   url: "/contacts/index/save-contact/",
			   data: {list:list},
			   success: function(data){
						alert(oneSelected + 'Contact(s) added Sucussfully');
						window.location = '/contacts/';
						//$('#listContent').html('Contacts added successfully');
			   }
		});
	}
	
} 

//]]>
</script>
